🔹 Universal Selector (*
)
- Definition: Universal selector sabhi HTML elements ko target karta hai.
- Use-case: Base styling apply karna jaisa margin/padding reset, sabke liye ek consistent foundation.
- Syntax:
* { margin: 0; padding: 0; box-sizing: border-box; }
- Pros: Quick reset, sabhi elements ek jaisa style follow karte hain.
- Cons: Agar heavy rules rakhe, performance impact ho sakta hai, aur unwanted overrides ho sakte hain.
Hinglish: Universal Selector (*
) se hum sabhi elements ko ek saath style kar sakte
hain, jaise sabki margin aur padding reset karna. Yeh ek consistent base provide karta hai puro
page ke liye.
💻 Live Code Preview: Universal Selector
If the iframe doesn’t load, click here to open Universal Selector Demo .
🔹 Element (Type) Selector
- Definition: Element selector ek specific HTML tag ko target karta hai (e.g.,
p
,h1
). - Use-case: Sabhi paragraphs ko ek jaisa style dena—jaise font-size ya color set karna.
- Syntax:
h1 { color: blueviolet; font-size: 2rem; } p { font-size: 1rem; line-height: 1.5; }
- Pros: Simple aur straightforward. Direct tags pe style apply hoti hai.
- Cons: Agar same tag baar-baar use ho, overlapping rules ho sakte hain aur maintenance tough ho sakti hai.
Hinglish: Element Selector (jaise h1
ya p
) direct har us tag ko style
karta hai. Agar sabhi paragraphs ko ek jaisa look dena ho, tab yeh best hai. Lekin agar aapko
kuch specific paragraphs hi target karne hain, toh class ya ID better rehta hai.
💻 Live Code Preview: Element Selector
If the iframe doesn’t load, click here to open Element Selector Demo .
🔹 Class Selector (.classname
)
- Definition: Class selector ek ya adhik elements ko group karke style apply karta hai.
- Use-case: Alag-alag tags ko ek jaisa style dena—jaise kuch headings aur paragraphs.
- Syntax:
.note { background-color: #f9f9f9; padding: 10px; border-left: 4px solid #1a73e8; }
- Pros: Flexible, reuse across different elements.
- Cons: Agar class names descriptive nahi, CSS maintain karna mushkil ho sakta hai.
Hinglish: Class Selector (.classname
) se aap same style multiple HTML elements pe
laga sakte hain bina code duplicate kiye. Yeh ek consistent design pattern bana deta hai.
💻 Live Code Preview: Class Selector
If the iframe doesn’t load, click here to open Class Selector Demo .
🔹 ID Selector (#idname
)
- Definition: ID selector sirf ek unique element ko target karta hai jiski
id
same ho. - Use-case: Ek page ka specific heading ya section uniquely style karna.
- Syntax:
#header { background-color: #1a73e8; color: white; padding: 20px; }
- Pros: High specificity, direct unique element pe apply hota hai.
- Cons: Sirf ek element pe lagta hai. Agar multiple elements ko style karna ho, class better hoti hai.
Hinglish: ID Selector (#idname
) ek unique element ko target karta hai. Agar aapke
page mein koi special header hai jise alag style karna hai, toh ID best hai. Yaad rahe, ek ID
sirf ek bar use ho.
💻 Live Code Preview: ID Selector
If the iframe doesn’t load, click here to open ID Selector Demo .
🔹 Group Selector
- Definition: Group selector ek saath multiple selectors ko ek rule mein combine karta hai (comma-separated).
- Use-case: Kai elements ko same style dena, jaise headings aur paragraphs.
- Syntax:
h1, p, .highlight { color: #1a73e8; background-color: #e8f0fe; }
- Pros: Code DRY rehta hai, fewer lines of CSS.
- Cons: Agar selectors bahut zyada ho, readability hurt ho sakti hai.
Hinglish: Group Selector (h1, p, .highlight
) se aap same styling multiple elements
pe apply kar sakte hain ek hi rule se. Yeh CSS ko concise aur maintainable banata hai.
💻 Live Code Preview: Group Selector
If the iframe doesn’t load, click here to open Group Selector Demo .
🔹 Attribute Selector ([type="text"]
)
- Definition: Attribute selector un elements ko target karta hai jinmein specified attribute/value pair hota hai.
- Use-case: Form inputs ko style karna based on
type
, ya specific links jinkehref
patterns match karein. - Syntax:
input[type="text"] { border: 2px solid #1a73e8; padding: 8px; width: 200px; }
- Pros: Precise targeting bina extra classes ke.
- Cons: Complex selectors performance impact daal sakte hain agar nested ho.
Hinglish: Attribute Selector ([type="text"]
) se aap sirf woh inputs style kar sakte
hain jinke type="text"
hai, bina class add kiye. Yeh form styling ko bahut aasan
banata hai.
💻 Live Code Preview: Attribute Selector
If the iframe doesn’t load, click here to open Attribute Selector Demo .
🔹 Child Selector (parent > child
)
- Definition: Child selector sirf direct children ko target karta hai, nested descendants ignore karta hai.
- Use-case: Immediate child elements ko style karna without affecting deeper nested elements.
- Syntax:
ul > li { list-style-type: circle; color: #1a73e8; }
- Pros: Precise control, avoids unintended nested styling.
- Cons: Multiple levels ke liye alag-alag selectors likhne padhenge.
Hinglish: Child Selector (parent > child
) se aap sirf direct child elements ko
style kar sakte hain. Maan lo ek ul
ke andar li
hai, nested
li
ko ignore karega.
💻 Live Code Preview: Child Selector
If the iframe doesn’t load, click here to open Child Selector Demo .
🔹 Descendant Selector (ancestor descendant
)
- Definition: Descendant selector nested elements ko bhi include karke target karta hai, chahe wo kisi bhi level par ho.
- Use-case: Pura nested structure ke andar sab matching elements ko style karna.
- Syntax:
nav a { text-decoration: none; color: #1a73e8; }
- Pros: Flexible, deep nesting handle karta hai.
- Cons: Large DOM me slow ho sakta hai; specificity issues ho sakte hain.
Hinglish: Descendant Selector (ancestor descendant
) se aap container ke andar jitne
bhi elements match karte hain, un sabko style kar sakte hain. Chahe wo bahut nested ho.
💻 Live Code Preview: Descendant Selector
If the iframe doesn’t load, click here to open Descendant Selector Demo .
🔹 Pseudo-classes
(:hover, :first-child, :last-child, :visited, :link
)
- Definition: Pseudo-classes elements ko unki state ya position ke basis par style karti hain (hover, first-child, etc.).
- Use-case: Interactive styling, jaisa hover effect, list-item ki special styling, link states.
- Syntax:
a:hover { background-color: yellow; color: red; } li:first-child { font-weight: bold; color: blue; } li:last-child { font-style: italic; color: green; } a:visited { color: purple; } a:link { color: blue; }
- Pros: Bina JS ke small interactions implement kar sakte hain.
- Cons: Kuch pseudo-classes older browsers me support nahi karte (compatibility check zaroori hai).
Hinglish: Pseudo-classes (:hover
, :first-child
,
:last-child
, :visited
, :link
) se aap dynamic aur
position-based styling kar sakte hain. Jaise hover pe button ki styling change ho.
💻 Live Code Preview: Pseudo-classes
If the iframe doesn’t load, click here to open Pseudo-classes Demo .
🔹 Pseudo-elements (::before, ::after
)
- Definition: Pseudo-elements page ke specific parts (jaise first letter) ko style karte hain ya extra content insert karte hain.
- Use-case: Decorative content (like icons), first letter styling, bina HTML modify kiye extra elements add karna.
- Syntax:
p::first-letter { font-size: 2rem; color: #1a73e8; } div::after { content: "✨"; color: gold; }
- Pros: Bina HTML change kiye content aur styling add kar sakte hain.
- Cons: Complex pseudo-element combinations maintain karna thoda tricky ho sakta hai.
Hinglish: Pseudo-elements (::before
, ::after
) se aap bina HTML modify
kiye extra content insert kar sakte hain, jaisa paragraph ke pehle bulb icon add karna ya div ke
baad sparkle emoji.
💻 Live Code Preview: Pseudo-elements
If the iframe doesn’t load, click here to open Pseudo-elements Demo .
📑 Combined Selectors (main.html)
Hinglish: Agar aap chaahte hain ki ek hi page par sab selectors (Universal, Element, Class, ID, Group, Attribute, Child, Descendant, Pseudo-classes, Pseudo-elements) ek saath dekhen, tab aap niche diye gaye combined demo ko dekh sakte hain.
💻 Live Code Preview: All Selectors in One
If the iframe doesn’t load, click here to open Combined Selectors Demo (main.html) .